#include "StdAfx.h"
#include "ReverberationMonoXAPO.h"

ReverberationMonoXAPO::ReverberationMonoXAPO(int num, IXAudio2SourceVoice* pVoice):MonoEffectXAPO(num, pVoice)
{
	CreateFX(__uuidof(FXReverb),&pXAPO);
	
	IXAudio2SourceVoice* pSourceVoice = GetSourceVoice();

	descriptor.InitialState = true;
	descriptor.OutputChannels = 1;
	descriptor.pEffect = pXAPO;

	AddEffectDescriptor(descriptor);
	
	XAPOParameters.Diffusion = FXREVERB_DEFAULT_DIFFUSION;
	XAPOParameters.RoomSize = FXREVERB_DEFAULT_ROOMSIZE;

	chain.EffectCount = GetEffectCount();
	chain.pEffectDescriptors = GetEffectDescriptors();
	pSourceVoice->SetEffectChain(&chain);
	
	pSourceVoice->SetEffectParameters( GetNumberEffect(), &XAPOParameters, sizeof( FXREVERB_PARAMETERS ) );

}

ReverberationMonoXAPO::~ReverberationMonoXAPO(void)
{
	pXAPO->Release();
}


HRESULT ReverberationMonoXAPO::apply(BYTE* buffer, DWORD BufferSize, WAVEFORMATEXTENSIBLE* pWfx)
{
	EnableEffect();
	
	return S_OK;
}


float ReverberationMonoXAPO::SetDiffusion(float Diffusion)
{
	float OldDiffusion = GetDiffusion();
	if (Diffusion >= FXREVERB_MIN_DIFFUSION && Diffusion <= FXREVERB_MAX_DIFFUSION)
		XAPOParameters.Diffusion = Diffusion;
	return OldDiffusion;
}

float ReverberationMonoXAPO::SetRoomSize(float RoomSize)
{
	float OldRoomSize = GetRoomSize();
	if (RoomSize >= FXREVERB_MIN_ROOMSIZE && RoomSize <= FXREVERB_MAX_ROOMSIZE)
		XAPOParameters.RoomSize = RoomSize;
	return OldRoomSize;
}

float ReverberationMonoXAPO::GetDiffusion()
{
	return XAPOParameters.Diffusion;
}

float ReverberationMonoXAPO::GetRoomSize()
{
	return XAPOParameters.RoomSize;
} 


